﻿Imports System.Data
Imports System.Data.SqlClient
Imports System.Configuration
Imports System.IO


Partial Class admin_photogallery_addPhoto
    Inherits System.Web.UI.Page

    Private _AlbumID As Integer
    Public Property AlbumID() As Integer
        Get
            Return _AlbumID
        End Get
        Set(ByVal value As Integer)
            _AlbumID = value
        End Set
    End Property

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim UpPath As String
        Dim UpName As String

        AlbumID = Request.QueryString("AlbumID")
        UpPath = "C:\inetpub\wwwroot\Henson Family\"
        UpName = Dir(UpPath, vbDirectory)
        'If UpName = "" Then
        '    MkDir("C:\inetpub\vhosts\mmile.deftwebdevelopment.com\httpdocs\img\photogalnew\")
        'End If
    End Sub

    Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles btnSubmit.Click
        Dim uploads As HttpFileCollection
        uploads = HttpContext.Current.Request.Files

        Dim imageAdapter As New MainDbTableAdapters.ImagesTableAdapter()
        Dim aiAdapter As New MainDbTableAdapters.AlbumImagesTableAdapter()
        Dim ImgID As Integer
        Dim imgName As String
        Dim imgCap As String
        Dim filePath As String
        Dim imgHeight As Integer = 0
        Dim imgWidth As Integer = 0

        imgName = txtImgName.Text
        imgCap = txtCaption.Text


        For i As Integer = 0 To (uploads.Count - 1)

            If (uploads(i).ContentLength > 0) Then
                Dim fileName As String = System.IO.Path.GetFileName(uploads(i).FileName)

                filePath = "/img/photogal/" & fileName


                uploads(i).SaveAs("C:\inetpub\wwwroot\Henson Family\" & fileName)
                lblMessage.Text = "File Uploaded Sucessfully."
                ImgID = imageAdapter.InsertImage(User.Identity.Name, imgName, imgCap, fileName, imgHeight, imgWidth, False)
                'aiAdapter.Insert(AlbumID, ImgID)

                Try

                Catch Exp As Exception
                    lblMessage.Text = "Some Error occured."
                End Try

            End If

        Next i

        'Response.Redirect("editAlbum.aspx?AlbumID=" & AlbumID)
    End Sub
End Class
